/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package common;

import java.util.*;
import java.util.*;

public class shStack<T>
{
    private Vector<T>	stack = null;

    public shStack()
	{
	    stack = new Vector<T>();
	}

    public int size()
    {
	return stack.size();
    }

    public String toString()
    {
	String result = "";

	for(T item : stack)
	    {
		result += item.toString()+",";
	    }
	
	if(result.length() > 1)
	    {
		return result.substring(0, result.length() - 1);
	    }

 	return result;
    }

    public boolean isEmpty()
    {
	return stack.size() == 0;
    }

    /**
     *получить запись из стека.
     *@return возвращает верхушку стека. запись снимается со стека
     */
    public T pop()
    {
	//T top = stack.remove(stack.size() - 1);
	return stack.remove(stack.size() - 1);
    }
    
    /**
     *получить запись из стека.
     *@return возвращает верхушку стека. запись остается на стеке
     */
    public T top()
    {
	return stack.lastElement();
    }

    /**
     *положить запись на стек
     *@param itrm запись для вталкивания
     */
    public void push(T item)
    {
	stack.add(item);
    }

}